<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="ajax.jsp"%>
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用后台管理系统</title>
    <link rel="stylesheet" href="css/global.css">
    <link rel="stylesheet" href="css/table.css">
    <style>
        /* 重置样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* 页面主体 */
        body {
            font-family: sans-serif;
            background-color: #f5f5f5;
        }

        /* 表格 */
        table {
            width: 100%;
            border-collapse: collapse;
            border: 1px solid #ddd;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 5px;
        }

        th {
            text-align: center;
            background-color: #f2f2f2;
        }

        /* 操作按钮 */
        .button {
            padding: 5px 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 3px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
        }

        .button-delete {
            padding: 5px 10px;
            background-color: #f44336;
            color: white;
            border: none;
            border-radius: 3px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
        }

        a{
            cursor: pointer;
        }
    </style>
</head>
<body>
<script>
    function deleteComplain(url){
        axiosInstance.post(
            url,
            {
                headers: headersJson
            }
        ).then((res)=>{
            console.log(res.data);
            if (res.data.code == 200){
                console.log("删除成功");
                $('#msg').innerHTML = "删除成功";
                setTimeout(()=>{
                    $('#msg').innerHTML = "";
                    loadPage('/good/getAllGoods');
                }, 1500);
            }else {
                console.log("删除失败");
                $('#msg').innerHTML = "删除失败";
                setTimeout(()=>{
                    $('#msg').innerHTML = "";
                }, 1500);
            }
        }).catch((e)=>{
            console.log(e);
            console.log("删除出现异常");
            $('#msg').innerHTML = "删除出现异常";
            setTimeout(()=>{
                $('#msg').innerHTML = "";
            }, 1500);
        })
    }
</script>
<div class="main">
    <h2 style="text-align: center">意见反馈数据列表</h2>
    <div style="margin-top: 20px">
        <table class="table">
            <thead>
            <tr>
                <th style="text-align: center">用户</th>
                <th style="text-align: center">标题</th>
                <th style="text-align: center">内容</th>
                <th style="text-align: center">发布日期</th>
                <th style="text-align: center">状态</th>
                <th style="text-align: center">管理员回复</th>
                <th style="text-align: center" width="150">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${complainList}" var="complain">
                <tr align="center">
                    <td>${complain.username}</td>
                    <td>${complain.title}</td>
                    <td>${complain.contents}</td>
                    <td>${complain.createTime}</td>
                    <td>${complain.status}</td>
                    <td>${complain.reps}</td>
                    <td>
                            <%--						<c:if test="${complain.status eq '未回复' }">--%>
                        <a onclick="navigateTo('/complain/getComplainById?id=${complain.complainId}')" class="button">
                            <c:if test="${complain.status eq '未回复'}">
                                回复
                            </c:if>
                            <c:if test="${!(complain.status eq '未回复')}">
                                修改
                            </c:if>
                        </a>&nbsp;&nbsp;
                            <%--						</c:if>--%>
                        <a class="button-delete"
                           onclick="{if(confirm('确定要删除吗?')){
                               deleteComplain('/complain/deleteComplains/${complain.complainId}');
                           }return false;}">删除</a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>
